/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var store = require("store");
	var checkOutSettle = require("../store/checkOutSettle");
	var fetchProperties = require("../constant/fetchProperties");
	var onCreditForm = require("../component/onCreditForm");
	
    var instance = {
        initComponent: function (params,widget) {
        	var grid = new Grid({
        		parentNode: ".J-grid",
        		autoRender: false,
        		model: {
        			url: "api/checkinimplement/query",
        			params: function(){
        				var subnav = widget.get("subnav");
						var time = subnav.getValue("time");           
						var alliance = subnav.getValue("alliance");
						var destination = subnav.getValue("destination");
						var servicePoint = subnav.getValue("servicePoint");
						var statementStatus = subnav.getValue("statementStatus");
        				return{   //主表数据
        					"servicePoint":servicePoint,
        					"statementStatus":statementStatus,
        					"groupReserve.planItemGroup.planItem.destination":destination,
        					"groupReserve.planItemGroup.alliance":alliance,
        					"groupReserve.planItemGroup.checkInStatus":"Finish",
        					"groupReserve.checkOutDate":time.start,
        					"groupReserve.checkOutDateEnd":time.end,
        					"paymentMethod":subnav.getValue("paymentMethod"),
        					fetchProperties: fetchProperties.grid
        				};
        			},
        			columns: [{
        				name: "groupReserve.planItemGroup.planItem.startDate",
						label: "年度",
						format: "date",
						formatparams: {
							mode: "YYYY"
						}
        			},{
        				name: "groupReserve.planItemGroup.planItem.destination.name",
						label: "目的地"
        			},{
        				name: "groupReserve.checkInDate",
						label: "入住日期",
						format: "date",
						formatparams: {
							mode: "YYYY.MM.DD"
						}
        			},{
        				name: "groupReserve.checkOutDate",
						label: "退房日期",
						format: "date",
						formatparams: {
							mode: "YYYY.MM.DD"
						}
        			},{
        				name: "signUpNum",
						label: "报名人数"
        			},{
        				name: "groupReserve.planItemGroup.allianceOrg.name",
						label: "组团单位",
						format:function(value,row){
							if(row.groupReserve.planItemGroup.alliance==true){
								return row.groupReserve.planItemGroup.allianceOrg.name;
							}else{
								return row.groupReserve.planItemGroup.servicePoint.name
							}
						}
        			},{
        				name: "statementStatus.value",
						label: "状态"
        			},{
        				name: "statementDate",
						label: "结算日期",
						format: "date",
						formatparams: {
							mode: "YYYY.MM.DD"
						}
        			},{
        				name : "paymentMethods",
        				label : "结算方式",
        				format : function(value, row){
        					var str = "";
        					for(var i = 0; i < row.paymentMethods.length; i++){
        						if(i == 0){
        							str = row.paymentMethods[i].value;
        						}else{
        							str += "," + row.paymentMethods[i].value
        						}
        					}
        					return str;
        				}
					},{
        				name:"isSales",
        				label : "是否销账",
        				format :function(value, row){
        					if(row.isSales == null){
        						return "";
        					}else if(row.isSales){
        						return "已销账";
        					}else{
        						return "未销账";
        					}
        					return parseFloat(value).toFixed(2);
        				}
        			},{
        				name: "operate",
        				label: "操作",
        				format: "button",
        				formatparams: [{
        					id: "settle",
        					text: "结算",
        					handler: function(index,data,rowEL){
        						widget.handler.grid.handlerSettleClick(widget,data);
        					}
        				},{
        					id: "detail",
        					text: "查看",
        					handler: function(index,data,rowEL){
        						onCreditForm.initComponent(params,widget);
        						widget.handler.grid.handlerDetailClick(widget,data);
        						widget.detail = true;
        					}
        				}]
        			}]
        		}
        	});
        	widget.set("grid",grid);
        }
    };
    module.exports = instance;
});
